package com.raven.craft.code.generator.mysql.schema.excel;

import com.raven.craft.code.generator.config.MysqlContext;
import com.raven.craft.code.generator.mysql.repo.entity.Table;
import com.raven.craft.code.generator.mysql.schema.Section;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author raven
 * @date 2019-06-06 12:03
 */
@Getter
@Setter
@ToString
public class ExcelSchemaVo {

    private String title;

    private List<String> schemaTitles;
    private List<Section> sections;

    public ExcelSchemaVo(MysqlContext context, ExcelSchemaProperties properties) {
        this.title = context.getDatabase();
        this.schemaTitles = properties.getTitles();
        this.sections = getSections(context.getTables());
    }

    private List<Section> getSections(List<Table> tables) {
        return tables.stream()
                .map(table -> Section.getSection(schemaTitles, table))
                .collect(Collectors.toList());
    }


}